let form = layui.form
var layer = layui.layer;

form.verify({
  email: [/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, '邮箱格式不正确, 名称允许汉字、字母、数字，域名只允许英文域名']

})

var id = new URLSearchParams(location.search).get('id');
function read() {
  $.ajax({
    url: 'admin/users/' + id,
    success: function (res) {
      if (res.status === 1) return layur.msg('获取用户信息失败!')
      console.log(res)
      form.val('abc', res.data)
    }
  })
}
read();

$('form').on('submit', function (ev) {
  ev.preventDefault();
  let val = form.val('abc');
  val['id'] = id;

  $.ajax({
    url: 'admin/users',
    type: 'put',
    data: val,
    success: function (res) {
      if (res.status === 1) {
        return layer.msg(res.message)
      } 
      layer.msg(res.message)
      location.href = './user.html'
    }
  })
})

$('button:contains(重置)').on('click', function (ev) {
  ev.preventDefault();
  read()
})